/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('address-purification', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CorrectAddressRequest {
  appKey?: string(name='AppKey', example='Axqwerasdf1a'),
  defaultCity?: string(name='DefaultCity'),
  defaultDistrict?: string(name='DefaultDistrict'),
  defaultProvince?: string(name='DefaultProvince'),
  serviceCode?: string(name='ServiceCode', example='addrp'),
  text?: string(name='Text'),
}

model CorrectAddressResponseBody = {
  data?: string(name='Data'),
  requestId?: string(name='RequestId', description='RequestId', example='226BD68D-6208-4140-A6EC-2F2BF434B601'),
}

model CorrectAddressResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CorrectAddressResponseBody(name='body'),
}

async function correctAddressWithOptions(request: CorrectAddressRequest, runtime: Util.RuntimeOptions): CorrectAddressResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    body['AppKey'] = request.appKey;
  }
  if (!Util.isUnset(request.defaultCity)) {
    body['DefaultCity'] = request.defaultCity;
  }
  if (!Util.isUnset(request.defaultDistrict)) {
    body['DefaultDistrict'] = request.defaultDistrict;
  }
  if (!Util.isUnset(request.defaultProvince)) {
    body['DefaultProvince'] = request.defaultProvince;
  }
  if (!Util.isUnset(request.serviceCode)) {
    body['ServiceCode'] = request.serviceCode;
  }
  if (!Util.isUnset(request.text)) {
    body['Text'] = request.text;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CorrectAddress',
    version = '2019-11-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function correctAddress(request: CorrectAddressRequest): CorrectAddressResponse {
  var runtime = new Util.RuntimeOptions{};
  return correctAddressWithOptions(request, runtime);
}

model ExtractAddressRequest {
  appKey?: string(name='AppKey', example='Axqwerasdf1a'),
  defaultCity?: string(name='DefaultCity'),
  defaultDistrict?: string(name='DefaultDistrict'),
  defaultProvince?: string(name='DefaultProvince'),
  serviceCode?: string(name='ServiceCode', example='addrp'),
  text?: string(name='Text'),
}

model ExtractAddressResponseBody = {
  data?: string(name='Data'),
  requestId?: string(name='RequestId', description='RequestId', example='E0627DDE-28D7-4C00-A611-E047DF81AF05'),
}

model ExtractAddressResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ExtractAddressResponseBody(name='body'),
}

async function extractAddressWithOptions(request: ExtractAddressRequest, runtime: Util.RuntimeOptions): ExtractAddressResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    body['AppKey'] = request.appKey;
  }
  if (!Util.isUnset(request.defaultCity)) {
    body['DefaultCity'] = request.defaultCity;
  }
  if (!Util.isUnset(request.defaultDistrict)) {
    body['DefaultDistrict'] = request.defaultDistrict;
  }
  if (!Util.isUnset(request.defaultProvince)) {
    body['DefaultProvince'] = request.defaultProvince;
  }
  if (!Util.isUnset(request.serviceCode)) {
    body['ServiceCode'] = request.serviceCode;
  }
  if (!Util.isUnset(request.text)) {
    body['Text'] = request.text;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ExtractAddress',
    version = '2019-11-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function extractAddress(request: ExtractAddressRequest): ExtractAddressResponse {
  var runtime = new Util.RuntimeOptions{};
  return extractAddressWithOptions(request, runtime);
}

model ExtractNameRequest {
  appKey?: string(name='AppKey', example='Axqwerasdf1a'),
  defaultCity?: string(name='DefaultCity'),
  defaultDistrict?: string(name='DefaultDistrict'),
  defaultProvince?: string(name='DefaultProvince'),
  serviceCode?: string(name='ServiceCode', example='addrp'),
  text?: string(name='Text'),
}

model ExtractNameResponseBody = {
  data?: string(name='Data'),
  requestId?: string(name='RequestId', description='RequestId', example='3A9AB010-AC38-4E53-9D25-6B97238C2897'),
}

model ExtractNameResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ExtractNameResponseBody(name='body'),
}

async function extractNameWithOptions(request: ExtractNameRequest, runtime: Util.RuntimeOptions): ExtractNameResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    body['AppKey'] = request.appKey;
  }
  if (!Util.isUnset(request.defaultCity)) {
    body['DefaultCity'] = request.defaultCity;
  }
  if (!Util.isUnset(request.defaultDistrict)) {
    body['DefaultDistrict'] = request.defaultDistrict;
  }
  if (!Util.isUnset(request.defaultProvince)) {
    body['DefaultProvince'] = request.defaultProvince;
  }
  if (!Util.isUnset(request.serviceCode)) {
    body['ServiceCode'] = request.serviceCode;
  }
  if (!Util.isUnset(request.text)) {
    body['Text'] = request.text;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ExtractName',
    version = '2019-11-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function extractName(request: ExtractNameRequest): ExtractNameResponse {
  var runtime = new Util.RuntimeOptions{};
  return extractNameWithOptions(request, runtime);
}

model ExtractPhoneRequest {
  appKey?: string(name='AppKey', example='Axqwerasdf1a'),
  defaultCity?: string(name='DefaultCity'),
  defaultDistrict?: string(name='DefaultDistrict'),
  defaultProvince?: string(name='DefaultProvince'),
  serviceCode?: string(name='ServiceCode', example='addrp'),
  text?: string(name='Text'),
}

model ExtractPhoneResponseBody = {
  data?: string(name='Data', example='{"phone_extract":[{"start":8,"end":19,"type":"TEL","word":"1333333****"}],"time_used":{"rt":{"phone_extract":"0.014524221420288086"},"start":"1589800189.9369104"},"status":"OK"}'),
  requestId?: string(name='RequestId', description='RequestId', example='A602539D-A298-4643-A268-94F0B893C12F'),
}

model ExtractPhoneResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ExtractPhoneResponseBody(name='body'),
}

async function extractPhoneWithOptions(request: ExtractPhoneRequest, runtime: Util.RuntimeOptions): ExtractPhoneResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    body['AppKey'] = request.appKey;
  }
  if (!Util.isUnset(request.defaultCity)) {
    body['DefaultCity'] = request.defaultCity;
  }
  if (!Util.isUnset(request.defaultDistrict)) {
    body['DefaultDistrict'] = request.defaultDistrict;
  }
  if (!Util.isUnset(request.defaultProvince)) {
    body['DefaultProvince'] = request.defaultProvince;
  }
  if (!Util.isUnset(request.serviceCode)) {
    body['ServiceCode'] = request.serviceCode;
  }
  if (!Util.isUnset(request.text)) {
    body['Text'] = request.text;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ExtractPhone',
    version = '2019-11-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function extractPhone(request: ExtractPhoneRequest): ExtractPhoneResponse {
  var runtime = new Util.RuntimeOptions{};
  return extractPhoneWithOptions(request, runtime);
}

model GetAddressDivisionCodeRequest {
  appKey?: string(name='AppKey', example='Axqwerasdf1a'),
  defaultCity?: string(name='DefaultCity'),
  defaultDistrict?: string(name='DefaultDistrict'),
  defaultProvince?: string(name='DefaultProvince'),
  serviceCode?: string(name='ServiceCode', example='addrp'),
  text?: string(name='Text'),
}

model GetAddressDivisionCodeResponseBody = {
  data?: string(name='Data'),
  requestId?: string(name='RequestId', description='RequestId', example='F726DC5F-67A1-4FBF-B216-758D1A681B8A'),
}

model GetAddressDivisionCodeResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetAddressDivisionCodeResponseBody(name='body'),
}

async function getAddressDivisionCodeWithOptions(request: GetAddressDivisionCodeRequest, runtime: Util.RuntimeOptions): GetAddressDivisionCodeResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    body['AppKey'] = request.appKey;
  }
  if (!Util.isUnset(request.defaultCity)) {
    body['DefaultCity'] = request.defaultCity;
  }
  if (!Util.isUnset(request.defaultDistrict)) {
    body['DefaultDistrict'] = request.defaultDistrict;
  }
  if (!Util.isUnset(request.defaultProvince)) {
    body['DefaultProvince'] = request.defaultProvince;
  }
  if (!Util.isUnset(request.serviceCode)) {
    body['ServiceCode'] = request.serviceCode;
  }
  if (!Util.isUnset(request.text)) {
    body['Text'] = request.text;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetAddressDivisionCode',
    version = '2019-11-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getAddressDivisionCode(request: GetAddressDivisionCodeRequest): GetAddressDivisionCodeResponse {
  var runtime = new Util.RuntimeOptions{};
  return getAddressDivisionCodeWithOptions(request, runtime);
}

model GetAddressSimilarityRequest {
  appKey?: string(name='AppKey', example='Axqwerasdf1a'),
  defaultCity?: string(name='DefaultCity'),
  defaultDistrict?: string(name='DefaultDistrict'),
  defaultProvince?: string(name='DefaultProvince'),
  serviceCode?: string(name='ServiceCode', example='addrp'),
  text?: string(name='Text'),
}

model GetAddressSimilarityResponseBody = {
  data?: string(name='Data'),
  requestId?: string(name='RequestId', description='RequestId', example='F1BD3BD6-3510-4144-996A-B7FCA70A5F81'),
}

model GetAddressSimilarityResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetAddressSimilarityResponseBody(name='body'),
}

async function getAddressSimilarityWithOptions(request: GetAddressSimilarityRequest, runtime: Util.RuntimeOptions): GetAddressSimilarityResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    body['AppKey'] = request.appKey;
  }
  if (!Util.isUnset(request.defaultCity)) {
    body['DefaultCity'] = request.defaultCity;
  }
  if (!Util.isUnset(request.defaultDistrict)) {
    body['DefaultDistrict'] = request.defaultDistrict;
  }
  if (!Util.isUnset(request.defaultProvince)) {
    body['DefaultProvince'] = request.defaultProvince;
  }
  if (!Util.isUnset(request.serviceCode)) {
    body['ServiceCode'] = request.serviceCode;
  }
  if (!Util.isUnset(request.text)) {
    body['Text'] = request.text;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetAddressSimilarity',
    version = '2019-11-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getAddressSimilarity(request: GetAddressSimilarityRequest): GetAddressSimilarityResponse {
  var runtime = new Util.RuntimeOptions{};
  return getAddressSimilarityWithOptions(request, runtime);
}

model GetZipcodeRequest {
  appKey?: string(name='AppKey', example='Axqwerasdf1a'),
  defaultCity?: string(name='DefaultCity'),
  defaultDistrict?: string(name='DefaultDistrict'),
  defaultProvince?: string(name='DefaultProvince'),
  serviceCode?: string(name='ServiceCode', example='addrp'),
  text?: string(name='Text'),
}

model GetZipcodeResponseBody = {
  data?: string(name='Data', example='{"zipcode":"311500","time_used":{"rt":{"zipcode":"0.004756927490234375","complete":"0.020321130752563477","structure":"0.007731199264526367"},"start":"1589800854.316437"},"status":"OK"}'),
  requestId?: string(name='RequestId', description='RequestId', example='D0078DC6-8A1F-41A0-9A5F-A6B6443E9A65'),
}

model GetZipcodeResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetZipcodeResponseBody(name='body'),
}

async function getZipcodeWithOptions(request: GetZipcodeRequest, runtime: Util.RuntimeOptions): GetZipcodeResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    body['AppKey'] = request.appKey;
  }
  if (!Util.isUnset(request.defaultCity)) {
    body['DefaultCity'] = request.defaultCity;
  }
  if (!Util.isUnset(request.defaultDistrict)) {
    body['DefaultDistrict'] = request.defaultDistrict;
  }
  if (!Util.isUnset(request.defaultProvince)) {
    body['DefaultProvince'] = request.defaultProvince;
  }
  if (!Util.isUnset(request.serviceCode)) {
    body['ServiceCode'] = request.serviceCode;
  }
  if (!Util.isUnset(request.text)) {
    body['Text'] = request.text;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetZipcode',
    version = '2019-11-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getZipcode(request: GetZipcodeRequest): GetZipcodeResponse {
  var runtime = new Util.RuntimeOptions{};
  return getZipcodeWithOptions(request, runtime);
}

model StructureAddressRequest {
  appKey?: string(name='AppKey', example='Axqwerasdf1a'),
  defaultCity?: string(name='DefaultCity'),
  defaultDistrict?: string(name='DefaultDistrict'),
  defaultProvince?: string(name='DefaultProvince'),
  serviceCode?: string(name='ServiceCode', example='addrp'),
  text?: string(name='Text'),
}

model StructureAddressResponseBody = {
  data?: string(name='Data'),
  requestId?: string(name='RequestId', description='RequestId', example='3542CCCD-A58D-4D46-9772-CC214D2D1E32'),
}

model StructureAddressResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: StructureAddressResponseBody(name='body'),
}

async function structureAddressWithOptions(request: StructureAddressRequest, runtime: Util.RuntimeOptions): StructureAddressResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    body['AppKey'] = request.appKey;
  }
  if (!Util.isUnset(request.defaultCity)) {
    body['DefaultCity'] = request.defaultCity;
  }
  if (!Util.isUnset(request.defaultDistrict)) {
    body['DefaultDistrict'] = request.defaultDistrict;
  }
  if (!Util.isUnset(request.defaultProvince)) {
    body['DefaultProvince'] = request.defaultProvince;
  }
  if (!Util.isUnset(request.serviceCode)) {
    body['ServiceCode'] = request.serviceCode;
  }
  if (!Util.isUnset(request.text)) {
    body['Text'] = request.text;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'StructureAddress',
    version = '2019-11-18',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function structureAddress(request: StructureAddressRequest): StructureAddressResponse {
  var runtime = new Util.RuntimeOptions{};
  return structureAddressWithOptions(request, runtime);
}

